// 数组切割
export const toMatrix = (arr, n) => {
    let matrix = []
    // arr.length > 62500会溢出
    // let fn = (arr) => {
    //     matrix.push(arr.slice(0, n))
    //     if (arr.length > n) {
    //         fn(arr.slice(n))
    //     }
    // }
    // fn(arr, n)
    // return matrix
    let len = arr.length
    for (let i = 0; i < len; i++) {
        if (i % n === 0) {
            matrix[matrix.length] = [arr[i]]
        } else {
            matrix[matrix.length - 1].push(arr[i])
        }
    }
    return matrix
}

// 数组分组
export const groupBy = (arr, fn) => {
    let group = {}
    arr.forEach((t, i) => {
        let type = fn(t, i)
        group[type] = group[type] || []
        group[type].push(t)
    })
    return group
}